class AutoStationsController < ApplicationController
layout "main"
  before_filter :pre_session
  active_scaffold :auto_station do |config|
    config.label = '<br/>'
    config.list.per_page = 10
    config.actions = [:search, :list, :update, :create, :show]
    config.columns = [:id, :name, :province, :tel, :auto_course, :description, :image1, :image2, :image3, :image4, :map_code, :s_status, :round, :show_image1, :show_image2, :show_image3, :show_image4, :show_code]
    config.columns[:s_status].form_ui = :select
    config.columns[:s_status].options = {:options => %w[Active Inactive]}
    config.columns[:province].form_ui = :select
    config.columns[:province].options = {:options => Province.find(:all, :order => "th" ).map {|p| [p.th, p.th] }}
    config.columns[:auto_course].form_ui = :select
    config.columns[:auto_course].search_sql = 'courses.name'
    config.columns[:auto_course].sort_by :sql=>'courses.name'
    config.search.columns << :auto_course

    config.columns[:name].label = "ชื่อสนามสอบ"
    config.columns[:auto_course].label = "Course"
    config.columns[:province].label = "จังหวัด"
    config.columns[:tel].label = "โทรศัพท์"
    config.columns[:description].label = "รายละเอียด"
    config.columns[:image1].label = "รูปที่ 1"
    config.columns[:image2].label = "รูปที่ 2"
    config.columns[:image3].label = "รูปที่ 3"
    config.columns[:image4].label = "รูปที่ 4"
    config.columns[:show_image1].label = "รูปที่ 1"
    config.columns[:show_image2].label = "รูปที่ 2"
    config.columns[:show_image3].label = "รูปที่ 3"
    config.columns[:show_image4].label = "รูปที่ 4"
    config.columns[:round].label = "รอบ"
    config.columns[:s_status].label = "Status"
    config.columns[:map_code].label = "Google Maps Iframe"
    config.columns[:show_code].label = "Google Maps"

    config.create.columns.exclude :id, :show_image1, :show_image2, :show_image3, :show_image4, :show_code, :round
    config.update.columns.exclude :id, :show_image1, :show_image2, :show_image3, :show_image4, :show_code, :round
    config.show.columns.exclude :id, :image1, :image2, :image3, :image4, :map_code
    config.list.columns.exclude :tel, :description, :image1, :image2, :image3, :image4, :map_code, :show_image1, :show_image2, :show_image3, :show_image4, :show_code
    config.list.sorting = {:id => 'ASC'}
  end

  def pre_session
    if !isadmin?
      redirect_to :controller=>"main"
    end
  end
end
